package Client;

import SQL.Connections;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;

public class AdminFindPeople extends JFrame{
    private JFrame frame;
    private JButton 退出Button;
    private JPanel j1;
    private JFormattedTextField formattedTextField1;
    private JFormattedTextField formattedTextField2;
    private JFormattedTextField formattedTextField3;
    private JFormattedTextField formattedTextField4;
    private JFormattedTextField formattedTextField5;
    private JFormattedTextField formattedTextField6;
    private JFormattedTextField formattedTextField7;
    private JFormattedTextField formattedTextField8;
    private JFormattedTextField formattedTextField9;

    public AdminFindPeople() {
        退出Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AdminPage.initialize();
                frame.dispose();
            }
        });
    }

    public static void main(String[] args) {

    }
    public static void initialize(String IdCard) {
        AdminFindPeople adminFindPeople = new AdminFindPeople();
        adminFindPeople.frame=adminFindPeople;
        adminFindPeople.setTitle("乘客信息界面");
        adminFindPeople.setContentPane(adminFindPeople.j1);
        adminFindPeople.setLocationRelativeTo(null);
        adminFindPeople.pack();
        adminFindPeople.setVisible(true);

        //初始化界面信息
        Vector data = new Vector();
        try {
            Connections connections = new Connections();
            Connection con = connections.getConnection();
            Statement stm = con.createStatement();
            String sql = "select IdCardName,IdCardSex,IdCardNumber,IdCardBirthday,ClassTrainNumber,ClassNumber,ClassDepaturePlace,ClassGoalPlace,ClassDepatureTime " +
                    "from IdCard,Ticket,Classes where IdCardNumber=TIdCardNumber and TClassNumber=ClassNumber and IdCardNumber='"+IdCard+"'";
            ResultSet rs = stm.executeQuery(sql);
            while (rs.next()){
                adminFindPeople.formattedTextField1.setText((String) rs.getString("IdCardName"));
                adminFindPeople.formattedTextField2.setText((String) rs.getString("IdCardSex"));
                adminFindPeople.formattedTextField3.setText((String) rs.getString("IdCardNumber"));
                adminFindPeople.formattedTextField4.setText((String) rs.getString("IdCardBirthday"));
                adminFindPeople.formattedTextField5.setText((String) rs.getString("ClassTrainNumber"));
                adminFindPeople.formattedTextField6.setText((String) rs.getString("ClassNumber"));
                adminFindPeople.formattedTextField7.setText((String) rs.getString("ClassDepaturePlace"));
                adminFindPeople.formattedTextField8.setText((String) rs.getString("ClassGoalPlace"));
                adminFindPeople.formattedTextField9.setText((String) rs.getString("ClassDepatureTime"));

                adminFindPeople.formattedTextField1.setEditable(false);
                adminFindPeople.formattedTextField2.setEditable(false);
                adminFindPeople.formattedTextField3.setEditable(false);
                adminFindPeople.formattedTextField4.setEditable(false);
                adminFindPeople.formattedTextField5.setEditable(false);
                adminFindPeople.formattedTextField6.setEditable(false);
                adminFindPeople.formattedTextField7.setEditable(false);
                adminFindPeople.formattedTextField8.setEditable(false);
                adminFindPeople.formattedTextField9.setEditable(false);
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
